package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.UserDto;
import com.zzyl.entity.User;
import com.zzyl.vo.UserVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.annotation.PropertyKey;
import java.util.List;

@Mapper
public interface UserMapper {

    int deleteByPrimaryKey(Long id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<User> list);

    /**
     * 用户分页
     * @param userDto
     * @return
     */
    Page<UserVo> paginationQuery(UserDto userDto);

    List<UserVo> paginationQueryByDeptNo(String deptNo);

    String getDeptName(String deptNo);

    @Select("select post_name from sys_post where post_no = #{postNo}")
    String getPostName(String postNo);

    Page<User> selectPage(UserDto userDto);

    void enableDisable(Long id, String status);

    @Update("update sys_user set is_delete = 1 where id = #{userIds}")
    void deleteUser(String userIds);

    /**
     * 根据用户名查找用户对象
     * is_delete： 逻辑删除字段，在企业中重要的表数据不可以物理删除，要逻辑删除，设置is_delete=1代表删除，is_delete=0代表没有删除
     *             以后查询用户数据 is_delete=0
     * @param username
     * @return
     */
    @Select("select * from sys_user where username = #{username} and ifnull(is_delete,0)=0")
    UserVo findByUserName(String username);
}